Repository navigation
fix(daemon): bound upload ingress and finalization - #4721
Conversation
…ingress) Daemon ingress/upload-ticket residual layer of #4441, on current main: - Explicit Node ingress ceilings at the daemon HTTP constructor: 30s to receive request headers, 600s to receive a request body, replacing the Node defaults. Ingress-only; RPC execution keeps its own deadlines. - Upload routes (/upload, /upload/preflight, /upload/direct/*, /upload/finalize) admit a finite 600s aggregate at the request callback plus a 120s body-inactivity ceiling, renewed only by accepted body progress and never resetting the aggregate. Expiry and client disconnect abort owned work through the request stream with typed reasons (transfer_phase_timeout / transfer_ingress_deadline_exceeded). - The single-shot upload runs one joined pipeline (request -> byte cap -> file) owned by the ingress link: the signal destroys every stream with its typed reason, accepted (flushed) bytes renew only the inactivity ceiling, and the earliest failure is reported via resolveIngressFailure so an abort-owned generic AbortError maps back to the owner's typed reason without losing an earlier classified failure. Hash and extract phases check the owner and are provably bounded by the byte cap. - Resumable ticket idle timer renews on completed (flushed) body bytes, not only after a whole chunk appends. Finalize disarms the idle timer only after the incomplete/stat validation, so an incomplete finalize keeps the original idle lifetime and expiry cannot fire during an active valid finalize; terminal paths still clean up through closeEntry. - The direct chunk pipeline maps an aborted signal's owned typed reason deterministically (resolveIngressFailure) and rolls back to the pre-chunk offset on failure. Tests: constructed server settings, fake-timer ingress/ticket behavior, real loopback request-route evidence for progress (308/range/x-upload-offset framing preserved, idle lifetime renewed) and client cancellation (rollback, on-schedule expiry cleanup) with controlled timers installed before ticket creation, abort-reason mapping matrix, and regression tests that fail on the previous candidate code. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
residual) Threads the existing per-request ingress signal through the real finalize route and into the owned post-body pipeline, closing the residual where finalize hash/extraction/registration ran unbounded behind the ticket: - upload-http.ts: /upload/finalize passes ingress.signal through finalizeResumableUpload into serialized admission, post-body hash, owned extraction and materialization, and the artifact registration boundary (sendUploadedArtifactResponse refuses to register an aborted owner). Inactivity now stops at body completion on every route (bodyComplete()), so valid post-body work observes only the 600s aggregate. - resumable-upload.ts: finalize admission checks the owner after the close/cancel race check, preserving the close side's typed expiry error; incomplete finalizes still keep the original idle timer; terminal failures keep joined cleanup and rethrow the typed first failure via resolveIngressFailure. - resumable-upload-transfer.ts: computeUploadHash takes the owner signal (abort destroys the read stream with the typed reason); chunk receive reports body completion. - upload.ts: single-shot hash and extraction run under the same signal instead of only phase-boundary checks behind the byte cap. - artifact-archive.ts: extraction forwards the signal into extractArchiveSafely's owned stream; inherently synchronous fs calls (statSync, open/read/close, rename, existsSync/rmSync) are guarded by owner checks immediately before them. Tests: bodyComplete inactivity/aggregate split, pending-finalize admission abort with ticket recovery, mid-hash abort with typed reason and semantic cleanup (registry closed, temp dir removed), owned single-shot success and post-body cancellation, plus the existing ingress/ticket suites. Wire ledger digests and rationale updated for the changed upload-http handlers. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
Size Report
Startup median (7 runs, lower is better):
|
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Apex Sentinel: 3 new findings on a9aec49. The verdict and the full list are in the summary comment.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Apex Sentinel: 1 finding moved to a new line on 63c5d0d. The verdict and the full list are in the summary comment.
|
I found no defect in the code at 63c5d0d, but the tests do not yet prove the new route wiring. Both loopback tests in upload-http-ingress.test.ts look like they pass on base: base already refreshed the ticket per chunk and already rolled back on cancel. If 17 of 17 checks pass at 63c5d0d, and there are no conflicts. Before merge, the new loopback test above should land, and the reuse question below should be answered. Could Not blocking, and fine to take or leave: many of the ten The open thread on the unlinked timeout literals does not apply as written: the aggregate usually fires before How the 600 s per-request budget composes with the proxy route stays with #4441. The Node |
…s stall and post-body finalize Add the createDaemonHttpServer loopback regression requested on #4721: with faked setTimeout and real loopback I/O, a stalled partial PUT sees its connection close at exactly the 120 s body-inactivity ceiling and the ticket offset rolls back (a restart from byte 0 completes with 200), then a finalize whose post-body hash spends >120 s of fake time still succeeds under the 600 s aggregate, proving bodyComplete() suspends the inactivity ceiling on the real route. Fails on the base wiring (no 120 s close) and on a bodyComplete()-less finalize mutation (finalize answers 500 transfer_phase_timeout). Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
|
Pushed I kept the current ingress owner. The host-kit watchdog would cover inactivity, but the route still needs a separate aggregate timer, request teardown and typed failure mapping. Reusing the completed-write observer would also require generalizing its client request interface to file streams. All three earlier inline threads are resolved. The three loopback tests, typecheck and focused lint passed. Exact affected validation is queued on the shared lock. |
…s stall and post-body finalize Add the createDaemonHttpServer loopback regression requested on #4721: with faked setTimeout and real loopback I/O, a stalled partial PUT sees its connection close at exactly the 120 s body-inactivity ceiling and the ticket offset rolls back (a restart from byte 0 completes with 200), then a finalize whose post-body hash spends >120 s of fake time still succeeds under the 600 s aggregate, proving bodyComplete() suspends the inactivity ceiling on the real route. Fails on the base wiring (no 120 s close) and on a bodyComplete()-less finalize mutation (finalize answers 500 transfer_phase_timeout). Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
07e9122 to
d7e485d
Compare
|
The size report was generated for |
This comment has been minimized.
This comment has been minimized.
|
Thanks for the update. At d7e485d the loopback proof I asked for is in and fails without the fix, the reuse question has an answer, and the abort-error matching is fixed. All 18 checks pass and there are no conflicts. One defect remains before merge. The request-body inactivity timer on the two JSON routes can close a request that is still making progress (upload-http.ts:289). Preflight and finalize arm the 120-second timer and read the body with Could The open inline thread on the abort cleanup near Not blocking: The new loopback test arms the admission timer and the post-write re-arm at the same fake time, so it would not catch a route that drops |
|
Pushed The shared phase watchdog could own the 120-second phase and its typed reason. All four routes now have a progress signal that can call |
This comment has been minimized.
This comment has been minimized.
|
The earlier JSON-route finding from d7e485d (#4721 (comment)) is fixed at 142a2c9: bounded JSON reads now renew the request-body deadline, and a loopback regression covers that route. No new code problems were found, and an independent check confirmed the new test exercises the real routes. CI is green, with 17 of 17 checks passing on 142a2c9, and there are no conflicts. Nothing else from this review must happen before merge. Not blocking, and you can take or leave it: Of the three open inline threads, the abort-cleanup |
|
An independent second pass over 142a2c9 found four cancellation and timeout gaps on the upload routes. Remote clients can reach these routes, so please fix them before merge, even though each needs specific timing.
Not blocking, take or leave:
The JSON-route fix from the last review holds, and CI is green at 142a2c9. |
… routes - Observe the tar pipeline outcome at once and keep the typed cancellation reason. - Make ticket admission abortable for PUT and finalize without breaking serialization. - Keep the final chunk offset check inside the rollback boundary. - Close the connection after an early answer to an unfinished request body.
|
Fixes for the four gaps in the second-pass review. Head: The tests are in
The four route digests changed, so Validation: |
… pass the ingress signal to authorization - A per-socket close owner lingers while any request on the socket has an unread body; requests only register their interest, so a pipelined upload no longer restores the hard close under a later 308. - The tar entry writer checks the signal after each filesystem await and runs its pipeline under it, so no writer opens after cancellation. - Upload authorization and the auth hook context get the ingress signal; the hook await stops with the typed reason and a late result is not applied.
|
This round fixes the two Sentinel minor findings and the three gaps from the review at 4130732. Head: Each new test failed on the
The wire ledger has new digests and acks for the four upload routes, Validation: |
|
I reran the live 308 test on head The single-request test uses the real client The pipelined test sends two PUTs on one keep-alive socket: #1 is a valid 1 MiB chunk, and #2 is a chunked PUT from offset 0. The client keeps sending 16 MiB after #2's 308, and then resumes with a ranged PUT: Pipelined through the proxy fails, and the cause is in the proxy. The same failure occurs before this PR. With the pre-PR merge base The raw logs are in |
This comment has been minimized.
This comment has been minimized.
|
At f9628fb the three gaps from the earlier review are fixed and covered by tests. CI is green (18 checks) and there are no conflicts. A second, independent correctness pass over the upload routes found four more timing gaps, each reproduced with a scaled loopback or in-memory probe against the head's ingress owner. These routes are reachable by remote clients, so they need fixing before merge.
Not blocking: the tar regression at archive-extraction-tar.test.ts:35 covers cancellation before the writer opens, not with a write already in flight. The held-hook tests in upload-http-socket-ownership.test.ts assert the signal fires but not that the route's wait settles. The comment in http-server.ts:86 says the upload owner answers an expired body with a typed reason, but for an unfinished body it destroys the socket. The ledger rationale at ledger.json:571 still says "30s/600s header and body ceilings" instead of the derived request ceiling. These hold at this head: all four routes arm one ingress owner at admission; accepted bytes renew inactivity and body completion disarms it; byte caps are fixed and PUT ranges stay within the preflight size; ordinary cancellation joins the pipeline, restores the PUT's pre-chunk size and removes unregistered directories. The four earlier inline threads are settled and can be resolved: r4622377719, r4622377722, r4628305643, r4629041193. |
…rded deadlines - One ingress budget owner derives the native request ceiling from the header ceiling, the connections-checking interval, the upload aggregate and a margin, so Node never closes a progressing upload body before its owner does. - Expiry ends the exchange whatever the request stream state: a typed answer when none started, and a connection close only after this request's own answer flushes, so a queued pipelined request never closes the socket under an earlier answer. The handler keeps owning its filesystem work through rollback. - Aggregate and inactivity deadlines are recorded on the monotonic clock and checked before progress renewal, chunk offset commit, ticket creation, finalize steps and artifact registration, with the same typed expiry as the timers.
|
This round answers the review at f9628fb. Head: Each item has a test that failed on the
Recommended items (done):
Security pass:
Live 308 rerun at In every pipelined run, the client sent 16 MiB after the second 308 and the socket closed cleanly. I did not run pipelined through the proxy, because it fails before this PR too (see the earlier comment). The proxy and the daemon are stopped. The four settled threads (r4622377719, r4622377722, r4628305643, r4629041193) were already resolved. Validation: |
This comment has been minimized.
This comment has been minimized.
|
At 267495c the four gaps from the previous review have targeted regressions: slow headers at the native server boundary, a held finalize answered before the queued 308, a typed timeout before a pending final write is released, and recorded deadlines checked at the success boundaries. Transfer caps and ordinary cancellation ownership hold. A second, independent correctness pass still found four more ways to commit after a deadline, each reproduced with a scaled clock probe, so no label yet. Three of them share one shape: a deadline that has passed but whose timer callback has not run yet is missed at the point where something becomes externally visible.
Rather than add a check at each site, please make the ingress owner the only way to commit: one The fourth is different:
Please cover each with a clock-driven test that holds the timer callbacks. Not blocking:
|
|
Two more items at 267495c, from the line-by-line review that finished after the comment above:
|
…d end ticket expiry in response order - The ingress owner's commit() is the only way to answer, publish a ticket, register an artifact, commit a chunk offset or clear a deadline. It compares the recorded monotonic deadlines first and runs the shared expiry path when one passed before its timer callback ran. - A preflight ticket is provisional until its answer commits; a refused commit removes the new ticket and keeps an existing one for the same attempt. - Ticket expiry aborts the active receive through its own controller, and the chunk pipeline no longer owns the request stream, so a pipelined socket is never closed under an earlier answer. - An expired request with an unread body hands the socket to its close owner's lingering close after its own answer flushes, bounded by a short grace. - The ticket idle timer renews only after the request deadline check.
|
This round answers the review at 267495c and its addendum. Head: The ingress owner is now the only committer. Each item has a test that failed on the
Addendum 2, coverage for the existing commit points. These checks already existed at
Recommended items (done):
Security pass:
Live 308 rerun at In every pipelined run, the client sent 16 MiB after the second 308 and the socket closed cleanly. The proxy and the daemon are stopped. The wire ledger has new digests and acks for the four route handlers and Validation: |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Apex Sentinel: 1 new finding on bea8886. The verdict and the full list are in the summary comment.
|
At bea8886 every change asked for since 267495c is in, each with a clock-driven test that fails without it: one owner check of the recorded deadlines before anything becomes visible, provisional-ticket cleanup, ticket expiry reported through the request in response order, and the lingering close on the resumable path. No success answer or ticket is published outside that check. CI is green. A second, independent correctness pass found one remaining gap, on the route the resumable work did not touch, so no label yet: Single-shot Not blocking:
|
…ate failure answers - POST /upload reads its body through the same forwarder as the chunk pipeline (pipeRequestBody), so a deadline, an inactivity expiry, a disconnect or a byte cap fails the pipeline without destroying the request. The request keeps its socket, and the ingress answers and ends the exchange with its lingering close. - Release of an unread body (a byte cap, a length mismatch, an expired ticket, an early answer) uses the same lingering close with its short grace. - Failure answers and auth-hook or tenant-trust refusals go through the commit gate, so a deadline that passed first answers with its own typed expiry.
|
This round answers Sentinel r4633504073 and the CoS review at bea8886. Head: The fix is in Blocker: single-shot
Recommended items (all done):
Live at The new single-shot case uses real daemon timers: 64 KiB, a 125 s stall, then 4 MiB more. Direct, the client reads the typed 500, gets a FIN, and sees no reset. Through Security pass: every upload pipeline now keeps The wire ledger has new digests and acks for Validation: |
|
At cdd3c1d the single-shot One small last item, the same kind of close as the upload fix, so no label yet: An oversized JSON body on Not blocking:
|
This comment has been minimized.
This comment has been minimized.
…ngering close
readNodeHttpRequestBody refuses a declared length over its bound before reading
and reads with req.iterator({ destroyOnReturn: false }), so a refusal no longer
destroys the request and detaches its socket. The upload ingress answers the 400
and ends the exchange with its lingering close. Failure answers now send inside
commit(work), and the pipelined single-shot test is reworded as a guard.
|
This round answers the review at cdd3c1d. Head: Oversized JSON body on preflight or finalize.
Optional items (both done):
No wire digest changed. I did not rebase and did not merge Validation: |
|
This PR is ready at 52e3437. The last item is fixed: Not blocking, for a follow-up if you like:
|
Apex Sentinel · ✅ Approve · review of
|
| Command | What it does |
|---|---|
@apex-sentinel-staging note <context> |
Adds context; Sentinel re-checks the cited code |
@apex-sentinel-staging pivot <why> |
Says the finding is wrong; Sentinel re-checks the cited code |
@apex-sentinel-staging like |
Marks the finding as useful |
@apex-sentinel-staging dislike <why> |
Marks it as not useful, so it is not raised again |
On this conversation, comment @apex-sentinel-staging review to run a full review once again.
* origin/main: (70 commits) refactor(apple-runner): one RUNNER_ERROR_CODES row per runner error code with parity/docs gates (callstack#4774) fix(android): require acknowledgements for test IME typing (callstack#4722) feat(scroll): add scroll refresh for pull-to-refresh (callstack#4770) refactor(host-kit): add request Scope and use it for the wait capture deadline (callstack#4794) fix(android): let permission all change nothing on an app that declares no permissions (callstack#4796) fix(cli): replace the CLI session and generated remote config instead of rewriting them in place (callstack#4797) fix(host-kit): accept a group-writable script directory the user owns (callstack#4799) fix(cli): escape control characters at the CLI's stdout and stderr writes (callstack#4778) fix(audit): do not report rows under a persistent bar that scrolling reveals (callstack#4775) fix(daemon): refuse an unsafe state directory before first use (callstack#4783) refactor: settle remaining single-deadline races through settleWithin (callstack#4788) refactor(host-kit): settle deadline races via settleWithin with R87 race ratchet (callstack#4766) fix(android): authenticate and bound persistent snapshot helper sessions (callstack#4729) fix(daemon): bound upload ingress and finalization (callstack#4721) chore(gates): ratchet wire-published reason literals by value (R89) (callstack#4779) feat(audit): evaluate role-less clickable views on Android (callstack#4780) fix(mutation): keep umask-setting tests out of Stryker's thread pool (callstack#4785) feat(audit): report controls that share one accessible name (callstack#4771) fix(contracts): pair open runtime hints with their apply operation (callstack#4754) refactor(daemon): report startup progress over the launch channel instead of marker files (callstack#4777) ...
Summary
Apply the daemon’s upload time budget from HTTP admission through artifact registration. Accepted JSON chunks and completed file writes renew the inactivity timer. After body completion, the original aggregate deadline still applies. Cancellation joins owned work and cleans up unregistered artifacts. Incomplete finalize preserves the ticket’s original expiry.
Refs #4441.
Validation
Head
52e3437eb9. Localpnpm check:affected --runpassed all runnable checks with exactCommit=true, including unit, daemon-wire-compat (againstv0.21.41) and docs. Hosted checks restart at this head. The live evidence below is fromcdd3c1d791; this head changes only the JSON body refusal path and the failure-answer commit.cdd3c1d791: a real daemon andagent-device proxywere tested with the real remote upload client. All 40 of 40 single-request runs (20 direct, 20 proxy) read the mid-stream 308 and resumed at offset 1048576 with 2 PUTs and no reset. All 20 pipelined direct runs passed. A single-shot upload that stalls 125 s gets the typed 500, a FIN and no reset when direct. A pipelined streaming PUT through the proxy fails before this PR too; that limit is in the proxy, which this PR does not change.142a2c9,4130732,f9628fb,267495c,bea8886andcdd3c1d(an oversized JSON body now gets its 400 and a clean close).Earlier evidence at
142a2c93bb: slow JSON bodies over 180 s, a stalled PUT at exactly 120,000 ms, and finalize after 150 s of hash work.Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.